home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Control del ratón / CheckerWithChildren / CheckerChild.cs next >
Encoding:
Text File  |  2001-01-15  |  1.2 KB  |  47 lines

  1. //-------------------------------------------
  2. // CheckerChild.cs ⌐ 2001 by Charles Petzold
  3. //-------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class CheckerChild: UserControl
  9. {
  10.      bool bChecked = false;
  11.  
  12.      public CheckerChild()
  13.      {
  14.           ResizeRedraw = true;
  15.      }
  16.      protected override void OnClick(EventArgs ea)
  17.      {
  18.           base.OnClick(ea);
  19.  
  20.           bChecked = !bChecked;
  21.           Invalidate();
  22.      }
  23.      protected override void OnKeyDown(KeyEventArgs kea)
  24.      {
  25.           switch(kea.KeyCode)
  26.           {
  27.           case Keys.Enter:
  28.           case Keys.Space:
  29.                OnClick(new EventArgs());
  30.                break;
  31.           }
  32.      }
  33.      protected override void OnPaint(PaintEventArgs pea)
  34.      {
  35.           Graphics grfx = pea.Graphics;
  36.           Pen      pen  = new Pen(ForeColor);
  37.  
  38.           grfx.DrawRectangle(pen, ClientRectangle);
  39.  
  40.           if (bChecked)
  41.           {
  42.                grfx.DrawLine(pen, 0, 0, ClientSize.Width, ClientSize.Height);
  43.                grfx.DrawLine(pen, 0, ClientSize.Height, ClientSize.Width, 0);
  44.           }
  45.      }
  46. }
  47.